package bc.view;

import bc.model.HtmlContext;
import bc.model.Card;
import bc.model.Cards;

import bc.event.LaunchStart;
import bc.event.StageResize;

import bpmjs.Event;
import bpmjs.MouseEvent;
import bpmjs.Context;

import haxe.rtti.Infos;
import haxe.Timer;
import js.Lib;
import js.Dom;

using bpmjs.MooToolsAdapter;

class WebsitePresenter implements Infos
{
	@Inject
	public var htmlContext : HtmlContext;

	@Inject
	public var cards : Cards;
	
	@Inject
	public var cardPresenters : Array<CardPresenter>;
	
	private var cardsDiv : HtmlDom;
	
	public function new()
	{
	}
	
	@MessageHandler
	public function handleStageEvent(event : StageResize)
	{
		updateToWindowSize();
	}
		
	@MessageHandler
	public function handleLaunchStart(event : LaunchStart)
	{
		cardsDiv = Lib.document.createDiv();
		htmlContext.contentDiv.appendChild(cardsDiv);
		
		for (card in cards.all)
		{
			var cardPresenter = cardPresenters[card.index];
			cardsDiv.appendChild(cardPresenter.createElement(card));
		}

		updateToWindowSize();
	}
	
	private function updateToWindowSize()
	{
		cardsDiv.setStyle("left", cast htmlContext.windowWidth / 2);
		cardsDiv.setStyle("top", cast htmlContext.windowHeight / 2);
	}
}
